package com.ojoin.trade.common.utils.paynow;

import java.io.UnsupportedEncodingException;

/**
 * 3DES加密提供者
 * 
 * @author 韩彦伟
 * @since: 2012-09-14
 * @version: 1.0.0
 */
public class ThreeDESEncryptProvider {

	public static String encrypt(String data, String key) {
		try {
			return EncodeUtils.byte2HexString(DESUtils.Union3DesEncrypt(key
					.getBytes("utf-8"), BASE64.encode(data.getBytes())
					.getBytes()));
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
			return null;
		}
	}

	public static String decrypt(String data, String key) {
		try {
			return new String(BASE64.decode(new String(DESUtils
					.Union3DesDecrypt(key.getBytes("utf-8"),
							EncodeUtils.hexString2Byte(data)))), "utf-8");
		} catch (UnsupportedEncodingException e) {
			return null;
		}
	}
   
	public static String changePasswordProductToTest(String pwd) {

		String rpwd = "";
		//pwd = "63B33B73DCB3D599367FA4ED4EBDF079";
		// 正式库秘钥

		String DSEKey = "q94f85md4gfr4k6lsdc75u3k";// 3DES需要的key
		// 测试库秘钥
		String TDSEKey = "qwertyuikjhgfdsazxcvbnmk";// 3DES需要的key

		String password = ThreeDESEncryptProvider.decrypt(pwd, DSEKey);

		rpwd = ThreeDESEncryptProvider.encrypt(password, TDSEKey);

		return rpwd;
	}

}
